//
// Created by liushuai on 2021/2/14.
//

#include "common.h"
namespace common {
bool canConstruct(std::string ransomNote, std::string magazine) {
    std::unordered_map<char, int> freq;
    for (auto chars : magazine) {
        if (freq.count(chars))
            freq[chars] += 1;
        else
            freq[chars] = 1;
    }
    for (auto e : ransomNote) {
        if (freq.count(e)) {
            freq[e] -= 1;
            if (freq[e] < 0)
                return false;
        } else
            return false;
    }
    return true;
}
} // namespace common
